<!DOCTYPE html>

<html>
<link href="css/text.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8" />	
<script type="text/javascript" src="js/jquery.min.js"></script>
<head>
	
    <style>

			html, body {
				font-family: "Microsoft Yahei", "SimSun", Arial;
				font-size: 14px; 	 			
				background-color: #040404;
				color: #E0DEDE;
 
			}			
			body::-webkit-scrollbar {
			  width: 1px; /* 滚动条宽度 */
			}

			body::-webkit-scrollbar-thumb {
			  background-color: #1C1D21; /* 滚动条滑块颜色 */
			}
			.fixedBox,div{
				background-color: #040404;
				border: 0px solid #555555;				
				white-space: nowrap;	
			}	
			
			.fixedBox::-webkit-scrollbar {
				width: 0px;     
				height: 0px;				
			}		

		#title{
			margin:-5px 0px 0px 3px;
			border: 0px solid #FFFF88;
			padding: 3px;
			display: inline-block;
			color: #F9F9F9;
			background-color: #040404;		
		}
		
		#tag{
			margin:8px 5px -3px 5px;
			border: 1px solid #FFFF88;
			padding: 2px;
			display: inline-block;
			color: #F9F9F9;
		}
		#tag1{
			margin:8px 5px -3px 5px;
			border: 1px solid #FF0000;
			padding: 2px;
			display: inline-block;
			color: #FFFF00;
			background-color: #804040;
		}
		#tag2{	
			margin:8px 5px -3px 5px;
			border: 1px solid #FF0000;
			padding: 2px;
			display: inline-block;
			color: #FFFF00;
		}
		#tag3{	
			margin:8px 5px -3px 5px;
			border: 1px solid #FFBF80;
			padding: 2px;
			display: inline-block;
			color: #FFFFB9;
		}
		#tag4{	
			margin:8px 5px -3px 5px;
			border: 1px solid #FF0000;
			padding: 2px;
			display: inline-block;
			color: #FF80FF;
		}		
		#tag5{	
			margin:8px 5px -3px 5px;
			border: 1px solid #00FF00;
			padding: 2px;
			display: inline-block;
			color: #6FFFB7;
		}				    	
    	
    .container {
        display: flex;
    }
    .left {
        width: 20%;
    }
    .right {
        width: 80%;
        padding-left: 0px; /* 保持一定的间距 */
    }
    .date-label {
        cursor: pointer;
    }
		span {
			margin-left:15px;        
		}
        
    p {
    	margin: 4px 0px 4px 0px;
    }    
    
		li:hover {
		  background-color: rgb(46, 45, 45);
		}  
    
    </style>
</head>
<body>

<div class="container">
    <div class="left">
        <ul id="dateList">
            <!-- 这里的日期会由 JavaScript 动态生成 -->
        </ul>
    </div>
    <div class="right" style="margin:-10px 0px;">
        <div id="titleLabel" class="title"></div>
    </div>
</div>

<script>
	    var k = 0;  //切换股票
	    var code = '002105';
			var n = 0;  //数据个数

      window.onload = function () {
		// 生成日期标签并添加点击事件监听
		
		getSource();		
				
      };	

	   var sxConte="停止刷新";

	  function getSource() {	  
		var u = decodeURI(window.location.href);								
				if(u.indexOf("##") > -1){
					var gp = u.split('##');										
					code = gp[1];	
				}	
				var url = "https://applhb.longhuvip.com/w1/api/index.php?apiv=w31&c=Stock&a=GetNewOneStockInfo&Type=0&StockID=" +　code ; 								
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {

						var dateListElement = document.getElementById('dateList'); 
						dateListElement.innerHTML = '<p><span id="shuaxin" style="display: inline-block; padding: 4px 8px; background-color: red; color: white; border-radius: 4px; cursor: pointer;" onclick="updatex();"> '+sxConte+' </span></p>';
						  
							var i = 0
					    data.OnTimeList.forEach(function (date) {
					    	if (i < 20){
					        var li = document.createElement('li');
					        li.textContent = date;
					        li.classList.add('date-label');
					        li.addEventListener('click', function () {
					            lhb(code,date);
								z = "0";			
								aObj = document.getElementById('shuaxin');
								if(aObj.innerText.trim() == "停止刷新"){					
									aObj.innerText = "自动刷新";
									sxConte = "自动刷新";
									aObj.style.color = "#ADFF2F";
								}
					        });
					        dateListElement.appendChild(li);
					      }
					      i++;  
					    });
						lhb(code,data.OnTimeList[0]);  	
					}
				});	 
	  }

			function updatex() {				
					aObj = document.getElementById('shuaxin');
					if(aObj.innerText.trim() == "停止刷新"){
						z = "0";
						aObj.innerText= "自动刷新";
						sxConte = "自动刷新";
						aObj.style.color = "#ADFF2F";
					}else if(aObj.innerText.trim() == "自动刷新"){
						z = "1";
						aObj.innerText = "停止刷新";
						sxConte = "停止刷新";
						aObj.style.color = "#E5E5E5";					
					}
				}
			
			function updated() {
				z = "0";			
				aObj = document.getElementById('shuaxin');
				if(aObj.innerText.trim() == "停止刷新"){					
					aObj.innerText = "自动刷新";
					sxConte = "自动刷新";
					aObj.style.color = "#ADFF2F";
				}					
			}
      
      
			var z = "1";
			$(function () {
				setInterval(function () {
					if(z==="1"){
						getSource();
					} 
				}, 500);
			});    
      

			var div = document.getElementById('titleLabel');	
			
			function lhb(code,tt) {	
				
				var u = decodeURI(window.location.href);								
				if(u.indexOf("##") > -1){
					var gp = u.split('##');										
					if(code == gp[1]){
						k = 0;						
					}else{
						code = gp[1];	
						k = 1;
					}				
				}	
				
				var url = "https://applhb.longhuvip.com/w1/api/index.php?apiv=w31&c=Stock&a=GetNewOneStockInfo&Type=0&StockID=" +　code + "&Time=" + ((tt == null )? getToday():tt); 								
				var ytdbusin = "";
				console.log(url);
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						
						if (k == 1){
					    // 生成日期标签并添加点击事件监听
					    var dateListElement = document.getElementById('dateList');
							var i = 0
					    data.OnTimeList.forEach(function (date) {
					    	if (i < 20){
					        var li = document.createElement('li');
					        li.textContent = date;
					        li.classList.add('date-label');
					        li.addEventListener('click', function () {
					            lhb(code,date);
					        });
					        dateListElement.appendChild(li);
					      }
					      i++;  
					    });
					    tt = data.OnTimeList[0];
					    k = 0;
						}
				    n = data.List.length;						    
						div.innerHTML = "<p>" + data.Time + "<span>"+ data.Name + "</span><span>涨幅：" + data.QuoteChange + "</span><span>成交额：" + NumberTransform(data.Turnover) + "</span><span>换手率：" + NumberTransform(data.TurnoverRatio) + "%</span></p>";
						div.innerHTML += "<p>净买入额：" + NumberTransform(data.BuyIn) + "<span>关联营业部数：" + data.ToBusinessCount + "</span></p>";
						res = data.List;						
						//console.log(data);
					}
				});					

				for (var j = 0; j < res.length; j++){					
					var ly = res[j].UpReason;
					for (var i = 0; i < ly.length; i++){
						if(j == 0){
							if(i == 0){
								div.innerHTML += "<p style='float:left;margin:0px 0px 0px 0px;color:#00FFFF;width:98%;'>上榜理由：" + ly[i] + "</p>";
							}else{
								div.innerHTML += "<p style='float:left;margin:0px 0px -5px 0px;color:#00FFFF;width:98%;'>上榜理由：" + ly[i] + "</p>";
							}
						}else{
							div.innerHTML += "<p style='float:left;margin:10px 0px -10px 0px;color:#00FFFF;width:98%;'>上榜理由：" + ly[i] + "</p>";
						}
					}
					
					div.innerHTML += "<p style='float:left;margin-bottom:-10px;color:#FF8040;font-size:16px;'>买入营业部：" + "<span style='color:#FFFF00;font-size:14px;'>买入总计" + NumberTransform(res[j].BuyTotal) + "元</span></p>";					
					var div1 = createDiv("买入营业部");
					div.appendChild(div1);
					
					//console.log(res);
					
					for (var i = 0; i < res[j].BuyList.length; i++){
						var aa = res[j].BuyList[i];
						var id = aa.ID;
						var name = aa.Name;
						//alert(name)
						var px = aa.PX;
						var buy = aa.Buy;
						var sell = aa.Sell;
						var je = buy - sell;
						
						//逐笔交割数据
						var WEBDATACODE = code + "|" + (code[0] == "6" ? 1 : 0) + "|" + tt.replace(/-/g,"") + "|B|" + px; 
						var curl = 'http://www.treeid/dlghttp://hot.icfqs.com:7615/site/tdx_tg/fx/page_lhb_zbcj.html?flag=001&info=' + WEBDATACODE + '&color=0&bkcolor=1C1D21&tdxmyietitle=历史板块&tdxmyiewidth=888&tdxmyieheight=600&tdxmyielastpos=1&canchangesize=1'
						
						var yzp = "";
						var youZiIcon = aa.YouZiIcon;
						if(youZiIcon == 1){
							yzp = "一线游资";
						}else if(youZiIcon == 2){
							yzp = "顶级游资";					
						}else if(youZiIcon == 3){
							yzp = "知名游资";					
						}
						if(yzp != ""){
							yzp = "<span id='tag2'>" + yzp + "</span>";
						}
						
						var yzmc = "";
						var groupicon = aa.GroupIcon[0];
						if(groupicon != undefined){
							yzmc = "<span id='tag3'>" + groupicon + "</span>";
						}
						
						var gl = "";
						var associcon = aa.AssocIcon;
						if(associcon == 1){
							gl = "<span id='tag1'>关联</span>";
						}
						
						var zb = "";
						var zs = "";
						if(ytdbusin != ""){
							var ystb = ytdbusin.buy;
							if(ystb != undefined){
								var aa = ystb[id];
								if(aa != undefined){
									zb = "<span id='tag4'>昨买" + aa + "</span>";
								}
							}
							
							var ysts = ytdbusin.sell;
							if(ysts != undefined){
								var aa = ysts[id];
								if(aa != undefined){
									zs = "<span id='tag5'>昨卖" + aa + "</span>";
								}
							}
						}
						
						div1.innerHTML += "<p><a href='" + curl + "'>" + px + "." + name + "<span style='position:absolute;left:250px;color:#FF80FF;'>买：" + 
						NumberTransform(buy) + "</span><span style='position:absolute; left:330px;color:#00FF80;'>卖：" + NumberTransform(sell) + 
						"</span><span style='position:absolute; left:410px;color:#fff;'>净额："+ NumberTransform(je) + "</span></a></p>";
						
						if(gl + yzp + yzmc + zb + zs != ""){
							div1.innerHTML += "<p style='margin:-15px 0px 0px 15px;'><a href='" + curl + "'>" + gl + yzp + yzmc + zb + zs + "</a></p>";
						}
					}
					
					div.innerHTML += "<p style='float:left;margin-bottom:-10px;color:#00FF80;font-size:16px;'>卖出营业部：" + "<span style='color:#FFFF00;font-size:14px;'>卖出总计" + NumberTransform(res[j].SellTotal) + "元</span></p>";			
					var div2 = createDiv("卖出营业部");
					div.appendChild(div2);
					for (var i = 0; i < res[j].SellList.length; i++){
						var aa = res[j].SellList[i];
						var id = aa.ID;
						var name = aa.Name;
						//alert(name)
						var px = aa.PX;
						var buy = aa.Buy;
						var sell = aa.Sell;
						var je = buy - sell;
						var yzp = "";
						var youZiIcon = aa.YouZiIcon;
						
						var WEBDATACODE = code + "|" + (code[0] == "6" ? 1 : 0) + "|" + tt.replace(/-/g,"") + "|S|" + px; 
						var curl = 'http://www.treeid/dlghttp://hot.icfqs.com:7615/site/tdx_tg/fx/page_lhb_zbcj.html?flag=001&info=' + WEBDATACODE + '&color=0&bkcolor=1C1D21'						

						
						if(youZiIcon == 1){
							yzp = "一线游资";
						}else if(youZiIcon == 2){
							yzp = "顶级游资";					
						}else if(youZiIcon == 3){
							yzp = "知名游资";					
						}
						if(yzp != ""){
							yzp = "<span id='tag2'>" + yzp + "</span>";
						}
						
						var yzmc = "";
						var groupicon = aa.GroupIcon[0];
						if(groupicon != undefined){
							yzmc = "<span id='tag3'>" + groupicon + "</span>";
						}
						
						var gl = "";
						var associcon = aa.AssocIcon;
						if(associcon == 1){
							gl = "<span id='tag1'>关联</span>";
						}
						
						var zb = "";
						var zs = "";
						//alert(JSON.stringify(ytdbusin))
						if(ytdbusin != ""){
							var ystb = ytdbusin.buy;
							if(ystb != undefined){
								var aa = ystb[id];
								if(aa != undefined){
									zb = "<span id='tag4'>昨买" + aa + "</span>";
								}
							}
							var ysts = ytdbusin.sell;
							if(ysts != undefined){
								var aa = ysts[id];
								if(aa != undefined){
									zs = "<span id='tag5'>昨卖" + aa + "</span>";
								}
							}
						}
						
						div2.innerHTML += "<p><a href='" + curl + "'>" + px + "." + name + "<span style='position:absolute;left:250px;color:#FF80FF;'>买：" + 
						NumberTransform(buy) + "</span><span style='position:absolute; left:330px;color:#00FF80;'>卖：" + NumberTransform(sell) + 
						"</span><span style='position:absolute; left:410px;color:#fff;'>净额："+ NumberTransform(je) + "</span></a></p>";
						
						if(gl + yzp + yzmc + zb + zs != ""){
							div2.innerHTML += "<p style='margin:-15px 0px 0px 15px;'><a href='" + curl + "'>" + gl + yzp + yzmc + zb + zs + "</a></p>";
						}
					}
				}
			}

			function getToday() {
			  let today = new Date();
			  let year = today.getFullYear();
			  let month = String(today.getMonth() + 1).padStart(2, '0'); // 注意月份是从 0 开始计数的，需要加 1
			  let day = String(today.getDate()).padStart(2, '0');
			  return year + '-' + month + '-' + day;
			}

    
		function NumberTransform(num) { 
			var result = parseFloat(num);
			if (isNaN(result)) {                    
			   return false;  
			}  				
			if(Math.abs(result) > 100000000){
				result = result / 100000000;
				result = result.toFixed(2) + "亿";
			}else if(Math.abs(result) > 10000){
				result = result/10000;
				result = result.toFixed(0) + "万";
			}
			return result;  
		}    
		
		function createDiv(a) { 		
		  divA = document.createElement('div');
		  divA.id = a;
			divA.className = "fixedBox";
			divA.style.position= "relative"; 
			divA.style.float= "left"; 					
			divA.style.left= "-20px"; 
			divA.style.width= "100%";	  
			divA.style.border = "1px solid #555555";
		  document.body.appendChild(divA);
			return divA;
		}
</script>

</body>
</html>
